var shop = layui.data('shop')

if (!shop.nickname) {
  layui.$('.off').addClass('active').siblings().removeClass('active')
} else {
  layui.$('.on').addClass('active').siblings().removeClass('active')
  layui.$('.nickname').text(shop.nickname)
}

axios.get('http://localhost:9000/carousel/list').then(res => {
  if (res.data.code === 1) {
    const images = res.data.list.map(item => `<div><img src="http://localhost:9000/${item.name}"></div>`).join('');

    // 动态构建轮播图的HTML内容
    const carouselHtml = `<div carousel-item>${images}</div>`;

    // 将动态内容插入到轮播图容器中
    document.querySelector('#carousel').innerHTML = carouselHtml;

    layui.carousel.render({
      elem: '#carousel', // 选择器
      width: '1200px', //设置容器宽度
      height: '600px',
      arrow: 'hover',
      anim: 'fade' //切换动画方式
    });
  }
})

layui.$(".self").on('click',function () {
  location.href = "./self.html"
})

layui.$(".logout").on('click',function () {
  var id = layui.data('shop').id
  var token = layui.data('shop').token
  axios.get(`http://localhost:9000/users/logout?id=${id}`, {
    headers: {
        'authorization': token
      }
  }).then(res => {
    if (res.data.code === 1) {
      layui.data('shop', null)
      location.href = "./index.html"
    }
  })
})